﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MochCraigslistDay19.Models;
using System.IO;

namespace MochCraigslistDay19.Controllers
{
    public class HomeController : Controller
    {
        //private Services craigslist;

        public HomeController() //When you construct HomeController, thats when you want to make it.
        {
            //craigslist = new Services();
        }

        public ActionResult Index()
        {
            List<ProductVM> model = ServiceSingleton.Instance.GetList();

            return View(model);
        }

        public ActionResult PeanutButters()
        {
            List<PeanutButterVM> model = ServiceSingleton.Instance.GetList()
                .OfType<PeanutButterVM>()
                .OrderBy(p => p.Price)
                .ToList();

            return View(model);
        }

        public ActionResult SmartPhones()
        {
            List<ProductVM> model = ServiceSingleton.Instance.GetList();

            return View(model);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(ProductVM model)
        {
            ServiceSingleton.Instance.AddToProducts(model);
            //craigslist.AddToProducts(model);
            return RedirectToAction("Index");
        }

    }
}